<template>
	<view :class="['merchants',{'pd0': userInfo}]">
		<view class="merchants-contents">
			<image src="https://master.shengejiaju.cn/web/static/images/merchant-01.png" mode="widthFix" @click="goContract"></image>
			<image src="https://master.shengejiaju.cn/web/static/images/merchant-02.png" mode="widthFix" @click="goContract"></image>
			<image src="https://master.shengejiaju.cn/web/static/images/merchant-03.png" mode="widthFix" @click="goContract"></image>
			<image src="https://master.shengejiaju.cn/web/static/images/merchant-04.png" mode="widthFix" @click="goContract"></image>
			<image src="https://master.shengejiaju.cn/web/static/images/merchant-05.png" mode="widthFix" @click="goContract"></image>
			<image src="https://master.shengejiaju.cn/web/static/images/merchant-06.png" mode="widthFix" @click="goContract"></image>
		</view>
		<view class="server-icon" @click="contactServer"><image src="https://master.shengejiaju.cn/web/static/images/server.png" mode="widthFix"></image></view>
		<view class="login" v-if="!userInfo"><button type="primary" @click="login" hover-class="">立即登录</button></view>
		<uni-popup type="center" ref="serverPop">
			<view class="serverPop">
				<view class="serverPop-tit">联系客服</view>
				<view><image :src="service_img" @longtap="toSave"></image></view>
				<view class="tips">长按即可保存二维码</view>
				<view><text @click="phoneCall">立即呼叫</text></view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: '',
				service_img: '',
				service_phone: ''
			};
		},
		onLoad() {
			
		},
		onShow() {
			if(uni.getStorageSync('userInfo')){
				this.$api.UserInfo().then(res => {
					uni.setStorageSync('userInfo',JSON.stringify(res.datas))
				})
				this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			}
			this.$api.HomeWeChat().then(res => {
				this.service_img = res.datas.service_img
				this.service_phone = res.datas.service_phone
				if(res.datas.is_show_store==2){
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return false
				}else{
					if(!this.userInfo && res.datas.is_show_store==1){
						uni.reLaunch({
							url: '/'
						})
					}else if(this.userInfo.role_type==2 || this.userInfo.role_type==11){
						uni.switchTab({
							url: '/pages/index/index'
						})
						return
					}
				}
			})
		},
		methods: {
			login(){
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			contactServer(){
				this.$refs.serverPop.open()
			},
			phoneCall(){
				uni.makePhoneCall({
					phoneNumber: this.service_phone.toString(),
					fail(callFail) {
						console.log(callFail)
					}
				})
			},
			save() {
				uni.getImageInfo({
					src: this.service_img,
					success: function(image) {
						uni.saveImageToPhotosAlbum({
							filePath: image.path,
							success: function() {
								uni.showToast({
									title: '图片保存成功',
									icon: 'none',
									duration: 2200
								});
							}
						});
					}
				});
			},
			toSave() {
				uni.showModal({
					title: '图片保存',
					content: '确定要保存图片吗',
					success: e => {
						if (e['confirm']) {
							this.save();
						}
					}
				});
			},
			goContract(){
				uni.showToast({
					icon: 'none',
					title: '签约流程正在开发',
					duration: 1500
				})
			}
		}
	}
</script>

<style lang="scss">
	.merchants{
		padding-bottom: 90rpx;
		&.pd0{
			padding-bottom: 0;
		}
		.merchants-contents {
			image{
				width: 100%;
				vertical-align: top;
			}
		}
		.login{
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 99;
			button{
				height: 90rpx;
				line-height: 90rpx;
				font-size: 30rpx;
				border-radius: 0;
			}
		}
		.server-icon{
			position: fixed;
			bottom: 300rpx;
			right: 20rpx;
			width: 110rpx;
			height: 110rpx;
			image{
				width: 110rpx;
				height: 110rpx;
			}
		}
		.serverPop{
			background-color: #FFF;
			padding: 20rpx;
			border-radius: 10rpx;
			.serverPop-tit{
				text-align: center;
				margin-top: 0;
			}
			view{
				margin-top: 20rpx;
				text-align: center;
				image{
					display: inline-block;
					width: 500rpx;
					height: 500rpx;
				}
				text{
					display: inline-block;
					border: solid 1px #2073F5;
					border-radius: 30rpx;
					height: 50rpx;
					line-height: 50rpx;
					color: #2073F5;
					padding: 0 30rpx;
					font-size: 28rpx;
					margin-bottom: 20rpx;
				}
			}
			.tips{
				font-size: 24rpx;
				color: #999;
				margin-top: 0;
				padding-bottom: 20rpx;
			}
		}
	}
</style>
